package com.whxy02.tolearn.app.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.whxy02.tolearn.app.beans.Card;
import com.whxy02.tolearn.app.dao.CardDao;
import com.whxy02.tolearn.app.service.CardService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class CardServiceImpl implements CardService {
    private QueryWrapper<Card> wrapper=new QueryWrapper<>();
    @Resource
    CardDao cardDao;


    @Override
    public List<Card> getAll() throws Exception {
        return cardDao.selectList(null);
    }

    @Override
    public Card getById(Integer id) throws Exception {
        return cardDao.selectById(id);
    }

    @Override
    public int save(Card card) throws Exception {
        return cardDao.insert(card);
    }

    @Override
    public int removeById(Integer id) throws Exception {
        return  cardDao.deleteById(id);
    }

    @Override
    public int change(Card card) throws Exception {
        return cardDao.updateById(card);
    }

    @Override
    public Page<Card> getByLimit(int now_page)throws Exception{
        Page<Card> page=new Page<>(now_page,5);
        return cardDao.selectPage(page,null);
    }

    @Override
    public Card getByUserId(Integer id) throws Exception {
        wrapper.clear();
        wrapper.eq("user_id",id);
        return cardDao.selectOne(wrapper);
    }
}
